﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Src="../Shared/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>回收管理</title>
    <uc1:Header ID="Header1" runat="server" />
    <script type="text/javascript" language="javascript">
        $(function () {
            $('#grid').datagrid({
                iconCls: 'icon-save',
                nowrap: false,                      //数据是否显示在一行里
                striped: true,                      //奇偶行使用不同背景色
                url: '/Package/HLoadAllByPage/40',           //从远程站点请求数据的 URL
                fitColumns: true,                   //适应表格的宽度并且防止水平滚动
                fit: true,
                idField: 'Id',                      //标识字段
//                sortName: 'HuiSSJ',                  //定义可以排序的列
//                sortOrder: 'asc',                   //定义列的排序顺序，只能用 'asc' 或 'desc'
                remoteSort: false,                  //定义是否从服务器给数据排序
                singleSelect: true,                //是否允许选中一行
                pagination: true,                  //分页
                rownumbers: true,                   //行号
                animate: true,                      //定义当节点展开或折叠时是否显示动画效果。
                pageSize: 20,                        //每页记录数
                pageList: [10, 20, 30],             //每页记录数列表
//                frozenColumns: [[
//	                { field: 'Id', checkbox: true}  //和列的特性一样，但是这些列将被冻结在左边
//				]],
                columns: [[
                    { field: 'TiaoMH', title: '条码号', width: 80 }
                    , { field: 'BaoMC', title: '包名称', width: 80 }
                    , { field: 'LingYKS', title: '领用科室', width: 80 }
                    , { field: 'LingYR', title: '领用人', width: 80, formatter: lingyrFormatter }
                    , { field: 'ShiYR', title: '使用人', width: 80, formatter: lingyrFormatter }
                    , { field: 'FaFRQ', title: '发放日期', width: 80 }
                    , { field: 'FaFSJ', title: '发放时间', width: 80 }
                    , { field: 'FaFR', title: '发放人', width: 80 }
                    , { field: 'HuiSRQ', title: '回收日期', width: 80 }
                    , { field: 'HuiSSJ', title: '回收时间', width: 80 }
                    , { field: 'HuiSR', title: '回收人/清洗人', width: 80 }
                ]]
            });
        });

        function submit() {
            $('#form').form('submit', {
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (msg) {
                    var msg1 = eval('(' + msg + ')');
                    if (msg1.IsSuccess) {
                        $.messager.alert('提示', "保存成功", 'info', function () {
                            $('#win').dialog('close');
                            $('#grid').datagrid('reload');
                        });
                    }
                    else {
                        $.messager.alert('提示', msg1.Message, "error");
                    }
                },
                error: function () {
                    $.messager.alert('错误', '保存失败！', "error");
                }
            });
        }

        function showdate(n) {
            var uom = new Date();
            uom.setDate(uom.getDate() + n);
            uom = uom.getFullYear() + "-" + (uom.getMonth() + 1) + "-" + uom.getDate();
            return uom;
        }

        function TiaoMH_onchange(tmh) {
            $.getJSON("/Package/GetFBaoMC/" + tmh, function (data) {
                $("#BaoMC").val(data.text);
                $("#BaoMC1").val(data.id);
                if (data.id != null && data.id.toString() != "") {
                    $('#grid').datagrid("reload");
                }
                $("#TiaoMH").val("");
                $("#TiaoMH").focus();
            });
        }

        function add() {
            $('#win').dialog({
                title: '回收',
                iconCls: 'icon-add',
                width: 400,
                height: 138,
                closed: false,
                cache: false,
                href: '/Package/HAdd/',
                modal: true,
                buttons: [{
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        $('#win').dialog('close');
                    }
                }],
                onLoad: function () {
                    $("#TiaoMH").change(function () {
                        TiaoMH_onchange($(this).val());
                    });
                    $("#TiaoMH").focus();
                }
            });
        }

        function save() {

            $.ajax({
                type: "POST",
                url: "/Package/HSave/",
                success: function (msg) {
                    if (msg.IsSuccess) {
                        $.messager.alert('提示', '回收成功！', "info", function () {
                            $('#grid').datagrid("reload");
                        });
                    }
                    else {
                        $.messager.alert('提示', msg.Message, "info");
                    }
                },
                error: function () {
                    $.messager.alert('错误', '回收失败！', "error");
                }
            });
        }

    </script>
</head>
<body class="easyui-layout">
    <div region="center" style="padding: 5px;" border="false">        
        <table id="grid" toolbar="#toolbar">
        </table>
        <div id="toolbar" style="padding: 2px; height: auto">
            <a id="btnAdd" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-add" plain="true" onclick="add()">回收</a>
            <a id="btnSave" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-save" plain="true" onclick="save()">确认回收</a>
        </div>
    </div>
    <div id="win" />
</body>
</html>
